package main.java.com.negromotad.genetics;

import java.util.List;

import org.jgap.GeneticOperator;
import org.jgap.IChromosome;
import org.jgap.Population;

public class TMSmartOperator implements GeneticOperator {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2706873198341211782L;

	public TMSmartOperator() {
	}

	@Override
	public void operate(Population a_population, List chromosomes) {
		int len = a_population.size();
		for (int i = 0; i < len; i++) {
			IChromosome chrome = (IChromosome) a_population.getChromosome(i)
					.clone();
			IChromosome chrome2 = (IChromosome) a_population.getChromosome(i)
					.clone();
			IChromosome chrome3 = (IChromosome) a_population.getChromosome(i)
					.clone();
			chrome.getGene(0).setAllele(
					(Integer) chrome.getGene(0).getAllele() + 1);
			chrome.getGene(1).setAllele(
					(Integer) chrome.getGene(1).getAllele() - 1);
			chrome2.getGene(2).setAllele(
					(Integer) chrome.getGene(2).getAllele() + 1);
			chrome2.getGene(1).setAllele(
					(Integer) chrome.getGene(1).getAllele() - 1);
			chrome3.getGene(1).setAllele(
					(Integer) chrome.getGene(2).getAllele() + 1);
			chrome3.getGene(0).setAllele(
					(Integer) chrome.getGene(1).getAllele() - 1);
			chrome3.getGene(2).setAllele(
					(Integer) chrome.getGene(2).getAllele() - 1);
			chromosomes.add(chrome);
			chromosomes.add(chrome2);
			chromosomes.add(chrome3);
		}
	}

}
